package com.popcorn.member.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.popcorn.action.Action;
import com.popcorn.action.ActionForward;
import com.popcorn.member.dao.MemberDAO;
import com.popcorn.member.model.MemberVo;

public class MemberUpdateAction implements Action {

	@Override
	public ActionForward execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String password = request.getParameter("member_password");
		String hp1 = request.getParameter("hp1");
		String hp2 = request.getParameter("hp2");
		String hp3 = request.getParameter("hp3");
		String hp = hp1+"-"+hp2+"-"+hp3;		
		HttpSession session = request.getSession();
		String User = (String) session.getAttribute("login");
		
		MemberDAO memberDao = new MemberDAO();
		MemberVo member = new MemberVo();
		member.setPwd(password);
		member.setHp(hp);
		member.setNickname(User);
		
		boolean result = false;
		result = memberDao.getUserUpdate(member);

		ActionForward forward = new ActionForward();
		
		if(result == true){
			session.invalidate();
			forward.setRedirect(false);
			forward.setPath("../main/main.jsp");
		}else{
			forward.setRedirect(false);
			forward.setPath("update_member.jsp");
		}	
		return forward;
	}

}
